/*
 * @Author: zhi1hw hanwei@zhi1tech.com
 * @Date: 2024-06-26 19:40:03
 * @LastEditors: zhi1hw hanwei@zhi1tech.com
 * @LastEditTime: 2024-06-26 19:50:35
 * @FilePath: \code\src\utils\VoiceAnnouncements.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
class VoiceAnnouncements {
    public synth = window.speechSynthesis // 启用文本
    public msg: any = new SpeechSynthesisUtterance()
    public language: string = 'zh-CN'  // 使用的语言:中文
    public volume: number = 1 // 音量
    public speed: number = 1  // 语速
    public pitch: number = 1 // 音高

    // 开始语音提示
    startVoiceFunction = (content: String) => {
        console.log(123123)
        this.msg.text = content
        this.msg.language = this.language
        this.msg.volume = this.volume
        this.msg.speed = this.speed
        this.msg.pitch = this.pitch
        this.synth.speak(this.msg)
    }
    // 停止语音提示
    stopVoiceFunction = (content: any) => {
        this.msg.text = content
        this.msg.language = this.language
        this.synth.cancel()
    }

}

//传出实例，保证整个系统只存在单例的Voice
const VoiceAnnouncementsInstance = new VoiceAnnouncements()

export default VoiceAnnouncementsInstance